import router from './router/index'

const whiteList = ['/login'] // no redirect whitelist
const defaultPath = '/list'
router.beforeEach((to, from, next) => {
    let token = sessionStorage.getItem('token')
    if (token) {
        if (to.path === '/login') {
            next({ path: defaultPath })
        } else {
            next()
        }
    } else {
        if (whiteList.indexOf(to.path) !== -1) {
            // 在白名单中，直接进入，无需token
            next()
        } else {
            next('/login') // 否则全部重定向到登录页
        }
    }
})
